package com.service.impl;

import com.dao.SysLogDao;
import com.pojo.SysLog;
import com.service.SysLogService;
import com.util.ConstUtils;
import com.vo.SysLogVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @author mornd
 * @date 2020/11/28 - 12:38
 */
@Service
@Transactional
public class SysLogServiceImpl implements SysLogService {
    @Autowired
    private SysLogDao sysLogDao;
    @Override
    public int saveLog(SysLog sysLog) {
        return sysLogDao.saveLog(sysLog);
    }

    @Override
    public List<SysLog> findSysLogList(SysLogVo sysLogVo) {
        return sysLogDao.findSysLogList(sysLogVo);
    }

    @Override
    public int deleteSysLog(Date appointDate) {
        return sysLogDao.deleteSysLog(appointDate);
    }

    /**
     * 删除超过日期的日志记录
     * @return
     */
    public boolean deleteSysLogByOverFolw(){
        try {
            //创建日历对象
            Calendar calendar = Calendar.getInstance();
            //要求如果删除当前时间之前的则第二个参数为负数之后为正数
            calendar.add(Calendar.DATE, 0 - ConstUtils.SYS_LOG_SAVE_DAY);
            int count = deleteSysLog(calendar.getTime());
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}
